<?php
namespace StarCloud\Models;

use Ramsey\Uuid\Uuid;
use StarCloud\Library\Exception;

trait ToolOrder
{
    // 32位
    public static function generateOrderNo()
    {
        $uuidString = Uuid::uuid4()->toString();

        $orderNo = static::ORDER_NO_PREFIX . substr(str_replace('-', '', $uuidString), 1, 31);
        if (self::findFirstByOrderNo($orderNo)) {
            throw new Exception('10001');
        }

        return $orderNo;
    }
}
